<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$this->model('task')->upzhanli();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'zhanli desc, createtime desc'
	);
	$list=$this->get_list('bangpai',$parameter,$total);
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['data']=$this->model('model')->getzhanli($item);
			$item['paixu']=$k;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'【温馨提示】：</br>1、帮众的流失，会带走订单，消费额！','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'帮派名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'url','title'=>'推广二维码','type'=>'ewm'),
			array('name'=>'zhanli','title'=>'帮派战力','type'=>'string'),
			array('name'=>'paixu','title'=>'帮派等级','type'=>'radio','options'=>'bangpais'),
			array('name'=>'data.gaogroup_num','title'=>'高级长老','type'=>'string'),
			array('name'=>'data.zhonggroup_num','title'=>'中级长老','type'=>'string'),
			array('name'=>'data.digroup_num','title'=>'普通长老','type'=>'string'),
			array('name'=>'data.all_num','title'=>'帮派人数','type'=>'string'),
			array('name'=>'data.all_fee','title'=>'帮订单总金额','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','op'=>'member','title'=>'他的帮众'),
		)),
		'search'=>array(
			array('type'=>'title','width'=>15,'name'=>'title','title'=>'帮派名称'),
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['bangpais']=$this->bangpais;
	exi($return);
}
if($_RQ['op']=='member'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['jianghu_id']=$_RQ['id'];
	$return['params']['id']=$_RQ['id'];
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_jianghu_myjia',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	$basic=$return['pluginset'];
	foreach($return['list'] as &$v){
		$v['member']=cfc('core')->member_show($v['mid']);
		$v['neili']=pdo_getcolumn('jy_jianghu_member',array('mid'=>$v['mid']),'neili');
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'【温馨提示】：</br>','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'neili','title'=>'内力','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		$this->delete('bangpai',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('bangpai',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>